//
//  UIButton+Extension.swift
//  weibo
//
//  Created by ForeverOSS on 16/2/10.
//  Copyright © 2016年 foreveross. All rights reserved.
//

import UIKit

extension UIButton {
    
    /// 使用 `图像名` 和 `背景图像名` 创建按钮
    ///
    /// - parameter imageName:     imageName
    /// - parameter backImageName: backImageName
    ///
    /// - returns: UIButton
    convenience init(imageName: String, backImageName: String) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
    }
    
    /// 便利构造函数
    ///
    /// - parameter title:         标题
    /// - parameter color:         字体颜色
    /// - parameter fontSize:      字号
    /// - parameter backImageName: 背景图像名称
    ///
    /// - returns: UIButton
    convenience init(title: String, color: UIColor, fontSize: CGFloat, backImageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
    }
}
